package services

import (
	"easyShop/core/config"
	"easyShop/core/database/mysql"
	"easyShop/model"
)

func GetRecommend() ([]model.Category, error) {
	mysqlConnect := mysql.GetConnect()
	var categoryRecommendList []model.Category
	query := mysqlConnect.Model(&model.Category{}).Select("id, icon, name").Where("recommend = ?", 1).Where("deleted_time is null").Find(&categoryRecommendList)

	if query.Error != nil {
		return categoryRecommendList, query.Error
	}

	if len(categoryRecommendList) > 0 {
		for k, v := range categoryRecommendList {
			categoryRecommendList[k].Icon = config.GetConfig("app_host").(string) + v.Icon
		}
	}

	return categoryRecommendList, nil
}
